/**
 * Power class,provide a static power() method to return the result of x power n.
 * @author Jarvan
 * @version 1.0
 * @create 2020/11/13 17:22
 */
public class Power {
    /**
     * Returns x power n(user recursion),use [static] to simplify the invoking.
     * @param x x
     * @param n n
     * @return returns x power n(user recursion)
     */
    public static double power(double x, int n) {
        if(n==0) {
            return 1;
        }
        if(n==1) {
            return x;
        }
        if(n==-1) {
            return 1/x;
        }

        double half= power(x,n/2);
        double rest= power(x,n%2);
        return half*half*rest;
    }

}
